import urllib.request
from urllib import request
from urllib.request import Request

from urllib3 import HTTPResponse

url = "http://www.weather.com.cn/weather1d/101010100.shtml"

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 SLBrowser/9.0.3.5211 SLBChan/105"
}

# 请求对象定制
my_request: Request = request.Request(url=url, headers=headers)

# 1. 获取Handler对象
handler = urllib.request.HTTPHandler()
# 2. 获取opener对象
opener = urllib.request.build_opener(handler)
# 3. 调用open()方法
response = opener.open(my_request)

print(response.read().decode("utf-8"))
